local skel = fk.CreateSkill {
  name = "lb__xianju",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lb__xianju"] = "衔炬",
  [":lb__xianju"] = "<b>锁定技</b>，首轮的最后一个回合结束后，你令所有角色依次获得一个额外回合，复原其武将牌并重置其<a href='#lb__xianju_round'><font color='red'>轮次类技能</font></a>的发动次数。",

  ["#lb__xianju_round"] = "#\"<b>轮次类技能</b>\"：技能描述中包含“每轮限X次”或“每轮[...]限X次”。",

  ["$lb__xianju1"] = "让刹那，成为永恒！",
  ["$lb__xianju2"] = "一步一步，踩下我们的脚印吧。",
  ["$lb__xianju3"] = "以爱为始的故事，也一定以爱为终。",
}

skel:addEffect(fk.GamePrepared, {
  can_trigger = Util.FalseFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, to in ipairs(room.players) do
      if to:isAlive() or to.rest > 0 then
        table.insert(room.extra_turn_list, { who = to, reason = skel.name }) --插到最后
        to:reset()
        for _, name in ipairs(to:getSkillNameList()) do
          local reset_skel = Fk.skill_skels[name]
          if reset_skel then
            local times_table
            if type(reset_skel.max_branches_use_time) == "function" then
              times_table = reset_skel:max_branches_use_time(to)
            else
              times_table = reset_skel.max_branches_use_time
            end
            if type(times_table) == "table" then
              for branch, scope_list in pairs(times_table) do   -- 只重置有分支的轮次技能
                if scope_list[Player.HistoryRound] then -- 不为nil就有限制
                  to:setSkillUseHistory(name)
                  break
                end
              end
            end
          end
        end
      end
    end
  end,
})

skel:addEffect(fk.RoundEnd, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name, true) and player.room:getBanner("RoundCount") == 1
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setTag(skel.name, true)
  end,
})

skel:addEffect(fk.RoundStart, {
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setTag(skel.name, nil)
  end,
})

return skel
